package com.yonyou.pmclouds.enterprise.process;

import com.yonyou.pmclouds.basecom.bp.processor.MultiProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.ref.itf.RefCodeConst;
import com.yonyou.pmclouds.basecom.ref.itf.ReferenceChecker;
import com.yonyou.pmclouds.enterprise.entity.EnterpriseVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashSet;

/**
 * @Author chulf
 * @Date 2020/4/18
 * @Description 校验删除企业是否被引用
 **/
@Component
public class DelCheckRefBeforeProcess implements MultiProcessor<EnterpriseVO> {

    @Autowired
    private ReferenceChecker referenceChecker;
    @Override
    public void process(EnterpriseVO[] vos, EnterpriseVO[] origs) throws BusinessException {

        HashSet<String> ids = new HashSet<>();

        for (EnterpriseVO vo : vos) {
            ids.add(vo.getPkEnterprise());
        }

        boolean flag = referenceChecker.checkReferenced(RefCodeConst.ENTERPRISE, ids.toArray(new String[0]));

        if (flag) throw new BusinessException("企业存在人员数据，不允许删除。");
    }
}
